﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MyWeb.Common;
using MyWeb.Business;
using MyWeb.Data;
namespace MyWeb.Admins{public partial class Product : System.Web.UI.Page{static bool Insert = false;protected void Page_Load(object sender, EventArgs e){if (!IsPostBack){Session["folder"] = "Product"; BindGrid();}}
private void BindGrid(){grdProduct.DataSource = ProductService.Product_GetByAll() ;grdProduct.DataBind();}
protected void btnThem_Click(object sender, EventArgs e){pnShow.Visible = false;pnUpdate.Visible = true;ControlClass.ResetControlValues(this);Session["upload"] = null;Insert=true;}
protected void btnXoa_Click(object sender, EventArgs e){try{DataGridItem item = default(DataGridItem);for (int i = 0; i < grdProduct.Items.Count; i++){item = grdProduct.Items[i];if (item.ItemType == ListItemType.AlternatingItem | item.ItemType == ListItemType.Item){if (((CheckBox)item.FindControl("ChkSelect")).Checked){string strId = item.Cells[1].Text;try{ProductService.Product_Delete(strId);}catch{}}}}grdProduct.CurrentPageIndex = 0;BindGrid();}catch{}}protected void grdProduct_ItemCommand(object source, DataGridCommandEventArgs e){Data.ProductInfo strCA=new ProductInfo();
string Id = e.CommandArgument.ToString();
if  (e.CommandName=="Edit"){DataTable dt = ProductService.Product_GetById(Id);txtId.Text=dt.Rows[0]["Id"].ToString();txtName.Text=dt.Rows[0]["Name"].ToString();txtDetail.Text=dt.Rows[0]["Detail"].ToString();txtPrice.Text=dt.Rows[0]["Price"].ToString();txtImage.Text=dt.Rows[0]["Image"].ToString();txtHSX.Text=dt.Rows[0]["HSX"].ToString();txtDate.Text=dt.Rows[0]["Date"].ToString();txtOrder.Text=dt.Rows[0]["Order"].ToString();txtStatus.Text=dt.Rows[0]["Status"].ToString();DropDownList1.SelectedValue =dt.Rows[0]["GroupProduct_Id"].ToString();txtOs.Text=dt.Rows[0]["Os"].ToString();txtProcessor.Text=dt.Rows[0]["Processor"].ToString();txtMemory.Text=dt.Rows[0]["Memory"].ToString();txtHD.Text=dt.Rows[0]["HD"].ToString();txtVM.Text=dt.Rows[0]["VM"].ToString();txtVC.Text=dt.Rows[0]["VC"].ToString();txtSC.Text=dt.Rows[0]["SC"].ToString();txtDirectX.Text=dt.Rows[0]["DirectX"].ToString();txtAge.Text=dt.Rows[0]["Age"].ToString();pnUpdate.Visible = true;pnShow.Visible = false;}else{ProductService.Product_Delete(Id);BindGrid();}}protected void lblBack_Click(object sender, EventArgs e){pnUpdate.Visible = false;pnShow.Visible = true;Insert=false;}protected void lblUpdate_Click(object sender, EventArgs e){string image = Session["upload"] == null ? "" : Session["upload"].ToString();
    
Data.ProductInfo obj=new Data.ProductInfo();obj.Id = txtId.Text;obj.Name = txtName.Text;obj.Detail = txtDetail.Text;obj.Price = txtPrice.Text;obj.Image = txtImage.Text;obj.HSX = txtHSX.Text;obj.Date = txtDate.Text;obj.Order = txtOrder.Text;obj.Status = txtStatus.Text;obj.GroupProduct_Id = DropDownList1.SelectedValue;obj.Os = txtOs.Text;obj.Processor = txtProcessor.Text;obj.Memory = txtMemory.Text;obj.HD = txtHD.Text;obj.VM = txtVM.Text;obj.VC = txtVC.Text;obj.SC = txtSC.Text;obj.DirectX = txtDirectX.Text;obj.Age = txtAge.Text;if (Insert == true){ProductService.Product_Insert(obj);}else{ProductService.Product_Update(obj);}BindGrid();pnShow.Visible = true;pnUpdate.Visible = false;Insert = false;
}protected void grdProduct_PageIndexChanged(object source, DataGridPageChangedEventArgs e){grdProduct.CurrentPageIndex = e.NewPageIndex;BindGrid();} protected void grdProduct_ItemDataBound(object sender, DataGridItemEventArgs e)
{
ListItemType itemType = e.Item.ItemType;if ((itemType != ListItemType.Footer) && (itemType != ListItemType.Separator)){if (itemType == ListItemType.Header){object checkBox = e.Item.FindControl("chkSelectAll");if ((checkBox != null)){((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelectAll_OnClick(this)");
}
}else{
string tableRowId = grdProduct.ClientID + "_row" + e.Item.ItemIndex.ToString();
e.Item.Attributes.Add("id", tableRowId);
object checkBox = e.Item.FindControl("chkSelect");
if ((checkBox != null))
{e.Item.Attributes.Add("onMouseMove", "Javascript:chkSelect_OnMouseMove(this)");
e.Item.Attributes.Add("onMouseOut", "Javascript:chkSelect_OnMouseOut(this," + e.Item.ItemIndex + ")");((CheckBox)checkBox).Attributes.Add("onClick", "Javascript:chkSelect_OnClick(this," + e.Item.ItemIndex + ")");}}}}
}
}